home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 05 / 32gdi / transfrm.c < prev    next >
C/C++ Source or Header  |  1992-09-01  |  3KB  |  96 lines

  1. /*-------------------------------------------
  2.    TRANSFRM.C -- Win32 Matrix Transform Demo
  3.                  (c) Charles Petzold, 1992
  4.   -------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <math.h>
  8.  
  9. #define TWOPI (2 * 3.14159)
  10.  
  11. LONG APIENTRY WndProc (HWND, UINT, DWORD, LONG) ;
  12.  
  13. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  14.                     LPSTR lpszCmdParam, int nCmdShow)
  15.      {
  16.      static char szAppName[] = "Transfrm" ;
  17.      HWND        hwnd ;
  18.      MSG         msg ;
  19.      WNDCLASS    wndclass ;
  20.  
  21.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  22.      wndclass.lpfnWndProc   = WndProc ;
  23.      wndclass.cbClsExtra    = 0 ;
  24.      wndclass.cbWndExtra    = 0 ;
  25.      wndclass.hInstance     = hInstance ;
  26.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  27.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  28.      wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  29.      wndclass.lpszMenuName  = NULL ;
  30.      wndclass.lpszClassName = szAppName ;
  31.  
  32.      RegisterClass (&wndclass) ;
  33.  
  34.      hwnd = CreateWindow (szAppName, "Matrix Transform Demo",
  35.                           WS_OVERLAPPEDWINDOW,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           CW_USEDEFAULT, CW_USEDEFAULT,
  38.                           NULL, NULL, hInstance, NULL) ;
  39.  
  40.      ShowWindow (hwnd, nCmdShow) ;
  41.      UpdateWindow (hwnd) ;
  42.  
  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.           {
  45.           TranslateMessage (&msg) ;
  46.           DispatchMessage (&msg) ;
  47.           }
  48.      return msg.wParam ;
  49.      }
  50.  
  51. LONG APIENTRY WndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
  52.      {
  53.      static short cxClient, cyClient ;
  54.      HDC          hdc ;
  55.      int          i ;
  56.      PAINTSTRUCT  ps ;
  57.      XFORM        xform ;
  58.  
  59.      switch (message)
  60.           {
  61.           case WM_SIZE:
  62.                cxClient = LOWORD (lParam) ;
  63.                cyClient = HIWORD (lParam) ;
  64.                return 0 ;
  65.  
  66.           case WM_PAINT:
  67.            hdc = BeginPaint (hwnd, &ps) ;
  68.  
  69.                SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
  70.  
  71.                for (i = 0 ; i < 180 ; i += 18)
  72.                     {
  73.                     xform.eM11 = (FLOAT)   cos (i * TWOPI / 360) ;
  74.                     xform.eM12 = (FLOAT) - sin (i * TWOPI / 360) ;
  75.                     xform.eM21 = (FLOAT)   sin (i * TWOPI / 360) ;
  76.                     xform.eM22 = (FLOAT)   cos (i * TWOPI / 360) ;
  77.                     xform.eDx  = (FLOAT) (cxClient / 2) ;
  78.                     xform.eDy  = (FLOAT) (cyClient / 2) ;
  79.  
  80.                     SetWorldTransform (hdc, &xform) ;
  81.  
  82.                     Ellipse (hdc, -cxClient / 4, -cyClient / 4,
  83.                                    cxClient / 4,  cyClient / 4) ;
  84.                     }
  85.  
  86.            EndPaint (hwnd, &ps) ;
  87.                return 0 ;
  88.  
  89.           case WM_DESTROY:
  90.                PostQuitMessage (0) ;
  91.                return 0 ;
  92.           }
  93.  
  94.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  95.      }
  96.